package com.irdstudio.efp.cus.service.impl;

import com.irdstudio.efp.cus.service.facade.CompanyWhiteListRecordService;
import org.apache.commons.lang3.StringUtils;
import org.apache.zookeeper.Op;

import java.util.*;
import java.util.stream.Stream;

/**
 * Description:企业白名单补录抽象类，封装规则
 * Date:2020/8/5 14:42
 * Create by :zhangbf
 */
public abstract class CompanyWhiteListAbstart implements CompanyWhiteListRecordService {

    private final String NAME_ONE="有限公司";
    private final String NAME_TWO="有限责任公司";
    private final String NAME_THR="股份有限公司";
    private final String NAME_FOUR="有限";

    /**
    *description：去掉有限公司，有限责任公司，股份有限公司后的所有字段，生成新的公司
    *param：企业名称
    *return: 新的企业名称
    *date: 2020/8/5 16:38
    *auther: gcb
    */
    public String getNewCompanyName(String companyName){
        if(StringUtils.isBlank(companyName)){
            return companyName;
        }
        if(companyName.contains(NAME_ONE)){
                companyName = companyName.substring(0,companyName.indexOf(NAME_ONE))+NAME_ONE;
                return companyName;
        }
        if(companyName.contains(NAME_TWO)){
                companyName = companyName.substring(0,companyName.indexOf(NAME_TWO))+NAME_TWO;
                return companyName;
        }
        if(companyName.contains(NAME_THR)){
                companyName = companyName.substring(0,companyName.indexOf(NAME_THR))+NAME_THR;
                return companyName;
        }
        return companyName;
    }

    /**
    *description：
    *param：companyName:企业名称
    *return:
    *date: 2020/8/6 17:01
    *auther: gcb
    */
    public Map<String,String> getRuleCompanyName(String dfCompanyName,String gjjCompanyName){
        Map<String,String> map = new HashMap<>();
        if(StringUtils.isBlank(dfCompanyName) && StringUtils.isNotBlank(gjjCompanyName)){
            map.put("gjjCompanyName",gjjCompanyName);
            return map;
        }
        if(StringUtils.isNotBlank(dfCompanyName) && StringUtils.isBlank(gjjCompanyName)){
            map.put("dfCompanyName",dfCompanyName);
            return map;
        }
        if(StringUtils.isBlank(dfCompanyName) && StringUtils.isBlank(gjjCompanyName)){
            return map;
        }
        if(dfCompanyName.equals(gjjCompanyName)){
            map.put("oneCompanyName",dfCompanyName);
            return map;
        }else{
            map.put("gjjCompanyName",gjjCompanyName);
            map.put("dfCompanyName",dfCompanyName);
        }
        return map;
    }

    /**
     * 将中文（）转换成英文()
     * @param companyName
     * @return
     */
    public String getEnglishCompanyName(String companyName){
        if(StringUtils.isNotBlank(companyName)){
            companyName = companyName.replace(" ","").replace("（","(").replace("）",")");
            return companyName;
        }
        return companyName;
    }

    /**
     * 将英文()转换为中文（）
     * @param companyName
     * @return
     */
    public String getChineseCompanyName(String companyName){
        if(StringUtils.isNotBlank(companyName)){
            companyName = companyName.replace("(","（").replace(")","）");
        }
        return companyName;
    }


    /**
     * 将英文()转换为中文（）
     * @param companyName
     * @return
     */
    public String getSpaceCompanyName(String companyName){
        if(StringUtils.isNotBlank(companyName)){
            companyName = companyName.replace(" ","");
        }
        return companyName;
    }

    /**
     * 公司名截取有限前面字段
     * @param companyName
     * @return
     */
    public String getLikeCompanyName(String companyName){
        if(companyName.contains(NAME_FOUR)){
            companyName = companyName.substring(0,companyName.indexOf(NAME_FOUR));
            return companyName;
        }
        return companyName;
    }



}
